package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/8 09:54
 * @apiNote
 */

public class Test00747DominantIndex {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4};
        int index = dominantIndex(nums);
        System.out.println(index);
    }
    public static int dominantIndex(int[] nums) {
        int max = 0;
        int max2 = 0;
        int index = -1;
        for(int i=0;i<nums.length;i++){
            if(nums[i] > max){
                max2 = max;
                max = nums[i];
                index = i;
            }else if (nums[i] > max2){
                max2 = nums[i];
            }
        }
        return max >= max2 * 2? index : -1;
    }
}
